package com.region.integral.common_user.obtain.dao.impl;
import org.springframework.stereotype.Component;

import com.region.integral.common_user.obtain.dao.IKCurrencyReward;
import com.region.integral.common_user.obtain.vo.IntegralData;
import com.region.integral.common_user.pojo.KCurrencyEntity;
import com.region.integral.exception.IntegralException;
import com.region.integral.hibernate.BaseHibernate;
import com.region.integral.util.CommonUserLogUtil;
@Component("ikCurrencyReward")
public class KCurrencyRewardImpl extends BaseHibernate implements IKCurrencyReward{
	@Override
	public void reward(int userid, int kNum, IntegralData integralData)
			throws IntegralException {
		
		KCurrencyEntity kcEntity = getKCurrencyEntity(userid);
		if (kcEntity != null) {
			int currk = kcEntity.getKcurrency();
			int maxKCurrency = kcEntity.getMaxKCurrency();
			int totalk = currk+ kNum;
			kcEntity.setKcurrency(totalk);
			if (maxKCurrency < totalk) {
				kcEntity.setMaxKCurrency(totalk);
			}
			System.out.println(userid+","+kNum);
			integralData.setSuccee(true);
			hibernateTemplate.update(kcEntity);
			hibernateTemplate.save(CommonUserLogUtil.log(userid, kNum, "reward"));	
		} 
		
	}
	
}
